home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 May
/
PCWorld_2008-05_cd.bin
/
Audio-video
/
audials
/
audialsTV-setup.exe
/
[0]
/
LaunchGadget.vbs
< prev
next >
Wrap
Text File
|
2008-03-13
|
6KB
|
200 lines
' VBScript source code
Main
sub Main
dim Version
dim AudialsWin32Path
AudialsWin32Path = """" & Wscript.Arguments.Named("p") & """"
Version = Wscript.Arguments.Named("v")
' Check if vista
if (Version >= 600) then
LaunchGadget()
else
' in case of XP start The audials TV win32
Set objApp = CreateObject("WScript.Shell")
objApp.Run AudialsWin32Path
end if
end sub
sub LaunchGadget()
dim Var
dim Path
dim PathGadget
dim Section
dim AllreadyInstalled
dim Result
'get system objects sidebar
Set oShell= CreateObject("WScript.Shell")
Path=oShell.ExpandEnvironmentStrings("%LOCALAPPDATA%") & "\Microsoft\Windows Sidebar\Settings.ini"
PathGadget=oShell.ExpandEnvironmentStrings("%LOCALAPPDATA%") & "\Microsoft\Windows Sidebar\Gadgets\MusicTV.Gadget"
' read settings
Section = -1
AllreadyInstalled = false
i = 0
Do
Var = "Section" & i
Result = GetINIString("Root",Var,"-1",Path)
if Result <> "-1" then
Section = i
if Result = "99" then
AllreadyInstalled = true
end if
end if
i = i + 1
Loop While i < 10
' is it installed?
if (not AllreadyInstalled) then
' shut down the sidebar first!
oShell.Run "TaskKill /f /im sidebar.exe /t", 0, true
wscript.sleep 1000
' write the initial ini
WriteINIString "Root","Section" & Section+1,"99",Path
' write the section code
WriteINIString "Section 99","PrivateSetting_GadgetName","""" & PathGadget & """",Path
WriteINIString "Section 99","PrivateSetting_Enabled","true",Path
end if
'start sidebar in all cases
oShell.Run "sidebar.exe", 0, false
end sub
'Work with INI files In VBS (ASP/WSH)
'v1.00
'2003 Antonin Foller, PSTRUH Software, http://www.motobit.com
'Function GetINIString(Section, KeyName, Default, FileName)
'Sub WriteINIString(Section, KeyName, Value, FileName)
Sub WriteINIString(Section, KeyName, Value, FileName)
Dim INIContents, PosSection, PosEndSection
'Get contents of the INI file As a string
INIContents = GetFile(FileName)
'Find section
PosSection = InStr(1, INIContents, "[" & Section & "]", vbTextCompare)
If PosSection>0 Then
'Section exists. Find end of section
PosEndSection = InStr(PosSection, INIContents, vbCrLf & "[")
'?Is this last section?
If PosEndSection = 0 Then PosEndSection = Len(INIContents)+1
'Separate section contents
Dim OldsContents, NewsContents, Line
Dim sKeyName, Found
OldsContents = Mid(INIContents, PosSection, PosEndSection - PosSection)
OldsContents = split(OldsContents, vbCrLf)
'Temp variable To find a Key
sKeyName = LCase(KeyName & "=")
'Enumerate section lines
For Each Line In OldsContents
If LCase(Left(Line, Len(sKeyName))) = sKeyName Then
Line = KeyName & "=" & Value
Found = True
End If
NewsContents = NewsContents & Line & vbCrLf
Next
If isempty(Found) Then
'key Not found - add it at the end of section
NewsContents = NewsContents & KeyName & "=" & Value
Else
'remove last vbCrLf - the vbCrLf is at PosEndSection
NewsContents = Left(NewsContents, Len(NewsContents) - 2)
End If
'Combine pre-section, new section And post-section data.
INIContents = Left(INIContents, PosSection-1) & _
NewsContents & Mid(INIContents, PosEndSection)
else'if PosSection>0 Then
'Section Not found. Add section data at the end of file contents.
If Right(INIContents, 2) <> vbCrLf And Len(INIContents)>0 Then
INIContents = INIContents & vbCrLf
End If
INIContents = INIContents & "[" & Section & "]" & vbCrLf & _
KeyName & "=" & Value
end if'if PosSection>0 Then
WriteFile FileName, INIContents
End Sub
Function GetINIString(Section, KeyName, Default, FileName)
Dim INIContents, PosSection, PosEndSection, sContents, Value, Found
'Get contents of the INI file As a string
INIContents = GetFile(FileName)
'Find section
PosSection = InStr(1, INIContents, "[" & Section & "]", vbTextCompare)
If PosSection>0 Then
'Section exists. Find end of section
PosEndSection = InStr(PosSection, INIContents, vbCrLf & "[")
'?Is this last section?
If PosEndSection = 0 Then PosEndSection = Len(INIContents)+1
'Separate section contents
sContents = Mid(INIContents, PosSection, PosEndSection - PosSection)
If InStr(1, sContents, vbCrLf & KeyName & "=", vbTextCompare)>0 Then
Found = True
'Separate value of a key.
Value = SeparateField(sContents, vbCrLf & KeyName & "=", vbCrLf)
End If
End If
If isempty(Found) Then Value = Default
GetINIString = Value
End Function
'Separates one field between sStart And sEnd
Function SeparateField(ByVal sFrom, ByVal sStart, ByVal sEnd)
Dim PosB: PosB = InStr(1, sFrom, sStart, 1)
If PosB > 0 Then
PosB = PosB + Len(sStart)
Dim PosE: PosE = InStr(PosB, sFrom, sEnd, 1)
If PosE = 0 Then PosE = InStr(PosB, sFrom, vbCrLf, 1)
If PosE = 0 Then PosE = Len(sFrom) + 1
SeparateField = Mid(sFrom, PosB, PosE - PosB)
End If
End Function
'File functions
Function GetFile(ByVal FileName)
Dim FS: Set FS = CreateObject("Scripting.FileSystemObject")
'Go To windows folder If full path Not specified.
If InStr(FileName, ":\") = 0 And Left (FileName,2)<>"\\" Then
FileName = FS.GetSpecialFolder(0) & "\" & FileName
End If
On Error Resume Next
GetFile = FS.OpenTextFile(FileName,1,false,-1).ReadAll
End Function
Function WriteFile(ByVal FileName, ByVal Contents)
Dim FS: Set FS = CreateObject("Scripting.FileSystemObject")
'On Error Resume Next
'Go To windows folder If full path Not specified.
If InStr(FileName, ":\") = 0 And Left (FileName,2)<>"\\" Then
FileName = FS.GetSpecialFolder(0) & "\" & FileName
End If
Dim OutStream: Set OutStream = FS.OpenTextFile(FileName, 2, True,-1)
OutStream.Write Contents
End Function